1. Field of the Invention
The present invention relates to a moving image encoding apparatus, a moving image encoding method, and a program which carry out two-step encoding such that the nature of an image to be encoded is analyzed on the basis of results of first-step encoding, and second-step encoding is carried out on the basis of results of the analysis.
2. Description of the Related Art
Techniques for encoding moving images have progressed together with the international standardization work. The reason for the standardization is that interoperability of decoding processing is needed in order to widely distribute encoded moving image contents. Currently, there exist various standard schemes such as MPEG (Moving Picture Experts Group)-1, MPEG-2, MPEG-4, and H. 264/AVC (Advanced Video Coding). Rules determined by these standard schemes are intended to secure the minimum interoperability for decoding processing, and there remains room for technical competition associated with realization of the standard schemes. Accordingly, many engineers conduct research and developments for, for example, shortening processing time and improving image quality.
For example, in order to mainly improve image quality, various schemes for performing two-step encoding have been proposed (see Patent Documents 1, 2, and 3).
In the scheme disclosed in Patent Document 1, statistical data are obtained for each frame through first-step encoding, frame-by-frame code-amount allocation for improving image quality is performed over the entire sequence of a moving image on the basis of the statistical data, and second-step encoding is performed in accordance with a variable bit rate.
In the scheme disclosed in Patent Document 2, first-step encoding is performed by use of a single quantization scale, and frame-by-frame code-amount allocation is performed on the basis of so-called complexity index data represented by, for example, the product of the quantization scale and the amount of generated codes.
In the scheme disclosed in Patent Document 3, by making use of a sample of statistical data obtained through first-step encoding performed by use of an appropriate quantization scale, and the amounts of codes generated by use of all other quantization scales (=quantization scales not used in the first-step encoding) are estimated by an approximated equation of an exponential function or a higher-order function. Subsequently, on the basis of the estimation result, frame-by-frame code-amount allocation is performed such that designated parameter conditions, such as a bit rate, are satisfied and image quality is improved to the greatest extent, and second-step encoding is performed.
Patent Document 1: Japanese Patent Application Laid-Open (kokai) No. H8-186821
Patent Document 2: Japanese Patent Application Laid-Open (kokai) No. 2003-18603
Patent Document 3: Japanese Patent Application Laid-Open (kokai) No. 2007-28156
However, Patent Document 1 merely contains, as a concrete example of optimal code-amount allocation, a graph showing a desired result (FIG. 6 of Patent Document 1) and a description “The optimal code-amount allocation is realized by performing code-amount allocation in accordance with the complexity of an input image in order to obtain a stable image within a range which satisfies the limitations of buffering and the maximum rate of a transmission line” (Paragraph No. 0038 of Patent Document 1). Therefore, Patent Document 1 cannot be said to describe a concrete operation of a moving image encoding apparatus for code-amount estimation.
In the scheme of Patent Document 2, the first-step encoding is performed only one time; that is, only one quantization scale is used, and only one set of statistical data (=the amount of codes generated through the first-step encoding) is used for the code-amount allocation processing. Therefore, the accuracy of the so-called complexity index data cannot be said to be sufficient, and the code-amount allocation cannot be performed properly.
In the scheme of Patent Document 3, as a concrete example of an approximated equation, there is used an equation in which the amount of codes is determined depending on the reciprocal of a quantization scale (Paragraph No. 0031 of Patent Document 3). Patent Document 3 describes that “In the first encoding, encoding is performed for each frame by use of a fixed quantization scale, the amount of codes generated for each frame is separated into a portion which is affected by the quantization and a portion (e.g., header) which is not affected by the quantization before being totaled . . . ” (Paragraph No. 0033 of Patent Document 3). That is, in the scheme of Patent Document 3, since the first encoding is performed for each frame by use of a fixed quantization scale, as in the case of the scheme of Patent Document 2, only statistical data for one quantization scale can be obtained for each frame. The above-described concrete example of the approximated equation contains only one coefficient which is determined with influence of the quantization. Therefore, the equation can be determined on the basis of only the statistical data for one quantization scale. However, since the model of the approximated equation itself cannot cope with various natures of images, the accuracy of generated code amount estimation cannot be said to be sufficient. Therefore, code amount allocation cannot be performed properly.
As described above, the conventional techniques described in Patent Documents 1 to 3 cannot properly perform code amount allocation, and cannot improve image quality.
Notably, a quantization scale is a value which defines coarseness of quantization. When the quantization scale is large, the compression efficiency increases although the amount of information lost through quantization increases. Meanwhile, when the quantization scale is small, the compression efficiency decreases although the amount of information lost through quantization decreases.
In contrast, a quantization parameter is a parameter used when quantization is carried out. The relation between the quantization scale and the quantization parameter is defined for each encoding scheme. When the quantization scale is represented by QS and the quantization parameter is represented by QP, the relation between QS and QP is QS=2(QP−4.0)/6 for H. 264/ACV, and QS=2×QP for MPEG-4. In the following description, “quantization control variable” is used as a term which encompasses both of the quantization scale and the quantization parameter.
The present invention has been accomplished in view of the above-described problems, and an object of the present invention is to provide a moving image encoding apparatus, a moving image encoding method, and a program which accurately estimate an amount of generated codes for each quantization control variable, and properly allocate a code amount for each frame.
Further, another object of the present invention is to provide a moving image encoding apparatus, a moving image encoding method, and a program which do not increase processing time significantly, while realizing accurate estimation of code amounts.
In order to achieve the above-described objects, the present invention provides a moving image encoding apparatus which carries out two-step encoding such that the nature of an image to be encoded is analyzed on the basis of results of first-step encoding, and second-step encoding is carried out on the basis of results of the analysis, the apparatus comprising first-step encoding means for executing a plurality of times the first-step encoding by use of different quantization control variables; code-amount estimation means for estimating, for all the quantization control variables, an amount of codes generated for each frame by making use of a plurality of results of the encoding by the first-step encoding means; code-amount allocation means for allocating an amount of codes for each frame on the basis of results of the estimation by the code-amount estimation means; and second-step encoding means for executing the second-step encoding on the basis of the amount of codes allocated to each frame by the code-amount allocation means.
Preferably, the first-step encoding means changes the number of times of execution of the encoding in accordance with the attribute of each frame. Further, preferably, the first-step encoding means omits a portion of processes contained in the coding process in the second and subsequent executions of the encoding process. Preferably, the code-amount estimation means selects a code-amount estimation logic for each frame. Further, preferably, the code-amount allocation means determines the quantization control variable such that the amount of codes for each frame, which is estimated by using the same quantization control variable becomes most suitable for a designated bit rate for an entire sequence of a moving image to be encoded, and allocates an amount of codes for each frame by using the determined quantization control variable.
The present invention also provides a moving image encoding method which carries out two-step encoding such that the nature of an image to be encoded is analyzed on the basis of results of first-step encoding, and second-step encoding is carried out on the basis of results of the analysis, the method comprising a first-step encoding step for executing a plurality of times the first-step encoding by use of different quantization control variables; a code-amount estimation step for estimating, for all the quantization control variables, an amount of codes generated for each frame by making use of a plurality of results of the encoding by the first-step encoding step; a code-amount allocation step for allocating an amount of codes for each frame on the basis of results of the estimation by the code-amount estimation step; and a second-step encoding step for executing the second-step encoding on the basis of the amount of codes allocated to each frame by the code-amount allocation step.
Preferably, the first-step encoding step changes the number of times of execution of the encoding in accordance with the attribute of each frame. Further, preferably, the first-step encoding step omits a portion of processes contained in the coding process in the second and subsequent executions of the encoding process. Preferably, the code-amount estimation step selects a code-amount estimation logic for each frame. Further, preferably, the code-amount allocation step determines the quantization control variable such that the amount of codes for each frame, which is estimated by using the same quantization control variable becomes most suitable for a designated bit rate for an entire sequence of a moving image to be encoded, and allocates an amount of codes for each frame by using the determined quantization control variable.
The present invention further provides a program which causes a computer to function as the moving image encoding apparatus of the present invention.
The present invention enables provision of a moving image encoding apparatus, a moving image encoding method, and a program which accurately estimate an amount of generated codes for each quantization control variable, and properly allocate a code amount for each frame. The present invention also enables provision of a moving image encoding apparatus, a moving image encoding method, and a program which do not increase processing time significantly, while realizing accurate estimation of code amounts.